load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//build:STRINGER.bzl", "stringer")

go_library(
    name = "sqlproxyccl",
    srcs = [
        "authentication.go",
        "backend_dialer.go",
        "conn_migration.go",
        "connector.go",
        "error.go",
        "error_source.go",
        "forwarder.go",
        "frontend_admitter.go",
        "metrics.go",
        "proxy.go",
        "proxy_handler.go",
        "query_cancel.go",
        "server.go",
        ":gen-errorcode-stringer",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/ccl/sqlproxyccl/acl",
        "//pkg/ccl/sqlproxyccl/balancer",
        "//pkg/ccl/sqlproxyccl/interceptor",
        "//pkg/ccl/sqlproxyccl/tenant",
        "//pkg/ccl/sqlproxyccl/tenantdirsvr",
        "//pkg/ccl/sqlproxyccl/throttler",
        "//pkg/roachpb",
        "//pkg/security",
        "//pkg/security/certmgr",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgwirebase",
        "//pkg/util/grpcutil",
        "//pkg/util/httputil",
        "//pkg/util/log",
        "//pkg/util/metric",
        "//pkg/util/netutil/addr",
        "//pkg/util/randutil",
        "//pkg/util/retry",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_jackc_pgproto3_v2//:pgproto3",
        "@com_github_pires_go_proxyproto//:go-proxyproto",
        "@com_github_prometheus_common//expfmt",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//codes",
        "@org_golang_google_grpc//credentials/insecure",
        "@org_golang_google_grpc//status",
    ],
)

go_test(
    name = "sqlproxyccl_test",
    size = "large",
    srcs = [
        "authentication_test.go",
        "backend_dialer_test.go",
        "conn_migration_test.go",
        "connector_test.go",
        "error_source_test.go",
        "forwarder_test.go",
        "frontend_admitter_test.go",
        "main_test.go",
        "metrics_test.go",
        "proxy_handler_test.go",
        "server_test.go",
    ],
    data = glob(["testdata/**"]),
    embed = [":sqlproxyccl"],
    exec_properties = {"test.Pool": "large"},
    shard_count = 8,
    deps = [
        "//pkg/base",
        "//pkg/ccl",
        "//pkg/ccl/sqlproxyccl/acl",
        "//pkg/ccl/sqlproxyccl/balancer",
        "//pkg/ccl/sqlproxyccl/interceptor",
        "//pkg/ccl/sqlproxyccl/tenant",
        "//pkg/ccl/sqlproxyccl/tenantdirsvr",
        "//pkg/ccl/sqlproxyccl/throttler",
        "//pkg/roachpb",
        "//pkg/security/certnames",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/server",
        "//pkg/sql",
        "//pkg/sql/catalog/descs",
        "//pkg/sql/pgwire",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/pgwire/pgwirebase",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/testcluster",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/metric",
        "//pkg/util/netutil/addr",
        "//pkg/util/randutil",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "@com_github_cockroachdb_cockroach_go_v2//crdb",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_jackc_pgconn//:pgconn",
        "@com_github_jackc_pgproto3_v2//:pgproto3",
        "@com_github_jackc_pgx_v4//:pgx",
        "@com_github_pires_go_proxyproto//:go-proxyproto",
        "@com_github_pires_go_proxyproto//tlvparse",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
        "@in_gopkg_yaml_v3//:yaml_v3",
        "@org_golang_google_grpc//codes",
        "@org_golang_google_grpc//status",
    ],
)

stringer(
    name = "gen-errorcode-stringer",
    src = "error.go",
    typ = "errorCode",
)
